package com.maserb.monitor.web.schoolStudent;


import com.alibaba.fastjson.JSONObject;
import com.maserb.monitor.service.schoolStudent.SchoolStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import java.util.UUID;

@Controller
public class GatewayController {

    @Autowired
    SchoolStudentService studentService;

    @RequestMapping("/gateway")
    @ResponseBody
    public JSONObject gateway(String merchantid, String appid, String apikey, String version, String body, String timestamp, String sign) {
        JSONObject result = new JSONObject();
        result.put("result", true);
        if(StringUtils.isEmptyOrWhitespace(apikey) || StringUtils.isEmptyOrWhitespace(body)) {
            result.put("result", false);
            result.put("errorCode", 1);
            result.put("errorMessage", "");
            result.put("errorCodeDescription", "apikey and body can not be null");
            result.put("data", null);
        } else {
            if(apikey.equals("Aedu.Trade.Exam.Upload.Url")) {
                result.put("Url", "http://47.97.191.172/studentScore/uploadScore");
                result.put("ExpirationTime", "2099-01-01");
                result.put("Token", UUID.randomUUID().toString());
            } else if(apikey.equals("Aedu.Trade.Exam.Upload.Result")) {
                result.put("Status", 0);
                result.put("Message", "处理中");
            } else if(apikey.equals("Aedu.Trade.Exam.Upload.ExamCreate")) {
                result.put("Url", "http://47.97.191.172/studentScore/uploadScore");
                result.put("ExpirationTime", "2099-01-01");
                result.put("Token", UUID.randomUUID().toString());
            }
        }

        return result;
    }
}
